<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>物料管理管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		
		function findtemplate(v) {
		
		    $.ajax({
		        type : "post",
		        async : false,
		        url : "${ctx}/sys/materiel/twiceClassData",
		        data : {
		            'useId' : v
		        },
		        dataType : "json",
		        success : function(msg) {
		            $("#classessTwiceId").empty();
		            $('#s2id_classessTwiceId').find('.select2-chosen').text('二级类目');
		            //$("#template").select2();
		            if (msg.length > 0) {
		                for (var i = 0; i < msg.length; i++) {
		                        var partId = msg[i].id;
		                        var partName = msg[i].name;
		                        var $option = $("<option>").attr({
		                            "value" : partId
		                        }).text(partName);
		                        $("#classessTwiceId").append($option);
		                }
		                //$("#template option:first").prop("selected", 'selected');
		                $("#classessTwiceId").change();
		               
		            }
		        },
		        error : function(json) {
		            $.jBox.alert("网络异常！");
		        }
		    });
		}
		
	   
		function findtemplate2() {
		var st=$("#classessTwiceId").val();
		    $.ajax({
		        type : "post",
		        async : false,
		        url : "${ctx}/sys/materiel/thirdClassData",
		        data : {
		            'useId' : st
		        },
		        dataType : "json",
		        success : function(msg) {
		            $("#classessThirdId").empty();
		            //$('#s2id_city').find('.select2-chosen').text('三级类目');
		            //$("#template").select2();
		            if (msg.length > 0) {
		                for (var i = 0; i < msg.length; i++) {
		                        var partId = msg[i].id;
		                        var partName = msg[i].name;
		                        var $option = $("<option>").attr({
		                            "value" : partId
		                        }).text(partName);
		                        $("#classessThirdId").append($option);
		                }
		                //$("#template option:first").prop("selected", 'selected');
		                $("#classessThirdId").change();

		            }
		        },
		        error : function(json) {
		            $.jBox.alert("网络异常！");
		        }
		    });
		}
		
		function pat(){
		     var partsCode=$("#partsCode").val();
		     $.ajax({
		    	 url:"${ctx}/sys/materiel/partsData",
		    	 type:"post",
		    	 dataType : "json",
		    	 data:{"code":partsCode},
		    	 success:function(data){
		    		if(data!=null) {
		    			$("#partsCnName").val(data.cnName);
		    		}
		    		 
		    	 }
		     })
		}
		$(function(){
			$("#classessOnceId").attr("disabled","disabled").css("background-color","#EEEEEE;");
			$("#classessTwiceId").attr("disabled","disabled").css("background-color","#EEEEEE;");
			$("#classessThirdId").attr("disabled","disabled").css("background-color","#EEEEEE;");
			$("#partsCode").attr("disabled","disabled").css("background-color","#EEEEEE;");
			$("#venderId").attr("disabled","disabled").css("background-color","#EEEEEE;");
		})
		 $(function(){
			var v=$("#classessOnceId").val();
			var vg=$("#classTwice").val();
			var vgs=$("#classThird").val()
			$.ajax({
		        type : "post",
		        async : false,
		        url : "${ctx}/sys/materiel/twiceClassData",
		        data : {
		            'useId' : v
		        },
		        dataType : "json",
		        success : function(msg) {
		            $("#classessTwiceId").empty();
		            $('#s2id_classessTwiceId').find('.select2-chosen').text('二级类目');
		            //$("#template").select2();
		            if (msg.length > 0) {
		                for (var i = 0; i < msg.length; i++) {
		                        var partId = msg[i].id;
		                        var partName = msg[i].name;
		                  
		                       if(vg==partId){
		       
		                    	   var $option = $("<option selected='selected'>").attr({
			                            "value" : partId
			                        }).text(partName);
		                       }else{
		                    	   var $option = $("<option >").attr({
			                            "value" : partId
			                        }).text(partName);
		                       }
		                        $("#classessTwiceId").append($option);
		                        
		                }
		            
		                $("#classessTwiceId").change();
		               
		            }
		        },
		        error : function(json) {
		            $.jBox.alert("网络异常！");
		        }
		    });
			
			var st=$("#classessTwiceId").val();
			    $.ajax({
			        type : "post",
			        async : false,
			        url : "${ctx}/sys/materiel/thirdClassData",
			        data : {
			            'useId' : st
			        },
			        dataType : "json",
			        success : function(msg) {
			            $("#classessThirdId").empty();
			            //$('#s2id_city').find('.select2-chosen').text('三级类目');
			            //$("#template").select2();
			            if (msg.length > 0) {
			                for (var i = 0; i < msg.length; i++) {
			                        var partId = msg[i].id;
			                        var partName = msg[i].name;
			                        if(vgs==partId){
			                        	
				                    	   var $option = $("<option selected='selected'>").attr({
					                            "value" : partId
					                        }).text(partName);
				                       }else{
				                    	   var $option = $("<option >").attr({
					                            "value" : partId
					                        }).text(partName);
				                       }
			                        $("#classessThirdId").append($option);
			                }
			                
			                $("#classessThirdId").change();

			            }
			        },
			        error : function(json) {
			            $.jBox.alert("网络异常！");
			        }
			    });
		}) 
		
	</script>
</head>
<body>
   <input name="classTwice" id="classTwice" value="${twices }" type="hidden"/>
   <input name="classThird" id="classThird" value="${thirds }" type="hidden"/>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/materiel/auditingMaterList">物料管理列表</a></li>
		<li class="active"><a href="${ctx}/sys/materiel/form?id=${materiel.id}">物料管理<shiro:hasPermission name="sys:materiel:edit">${not empty materiel.id?'详情':'添加'}</shiro:hasPermission><shiro:lacksPermission name="sys:materiel:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="materiel" action="${ctx}/sys/materiel/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<input name="ps" value="${ps }" type="hidden" />
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">配件编号：</label>
			<div class="controls">
				<form:input path="code" htmlEscape="false" maxlength="50" readonly="true" class="input-xlarge " />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">配件名称：</label>
			<div class="controls">
				<form:input path="partsCnName" htmlEscape="false" maxlength="50" readonly="true" class="input-xlarge " />
			</div>
		</div>
		
		<div class="control-group" >
			<label class="control-label">所属类目:</label>
			<div class="controls">
                 <form:select id="classessOnceId" path="classessOnceId" class="input-medium" onchange="findtemplate(this.options[this.options.selectedIndex].value);" >
			     <form:option value="" label="一级类目"/>
			     <form:options items="${classes}" htmlEscape="false" itemValue="id" itemLabel="name"/>
			     </form:select>
			     
			     <form:select id="classessTwiceId" path="classessTwiceId" class="input-medium" onchange="findtemplate2()"  >
			     <form:option value="" label="二级级类目"/>
			     </form:select>
			     
			     <form:select id="classessThirdId" path="classessThirdId" class="input-medium" >
			     <form:option value="" label="三级级类目"/>
			     </form:select>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">ERP码：</label>
			<div class="controls">
				<form:input path="erp" htmlEscape="false" maxlength="20" class="input-xlarge " readonly="true"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">物料名称：</label>
			<div class="controls">
				<form:input path="cnName" htmlEscape="false" maxlength="50" class="input-xlarge required" readonly="true"/>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">制造商品牌：</label>
			<div class="controls">
				<form:select id="venderId" path="venderId" class="input-medium required" readonly="true" disabled="disabled">
				<form:option value="" label="请选择制造商品牌"/>
			    <form:options items="${vender}" htmlEscape="false" itemValue="id" itemLabel="name"/></form:select>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">厂家编号：</label>
			<div class="controls">
				<form:input path="venderCode" htmlEscape="false" maxlength="50" readonly="true" class="input-xlarge required"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">物料描述：</label>
			<div class="controls">
				<form:input path="remark" htmlEscape="false" maxlength="255" class="input-xlarge " readonly="true"/>
			</div>
		</div>
		
		<div class="form-actions">
			<%-- <shiro:hasPermission name="sys:materiel:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission> --%>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>